package _set

import "container/list"

const base = 911

type MyHashSet struct {
	data []list.List
}

func Constructor() MyHashSet {
	return MyHashSet{data: make([]list.List, base)}
}

func hash(key int) int {
	return key % base
}

func (hs *MyHashSet) Add(key int) {
	if !hs.Contains(key) {
		index := hash(key)
		hs.data[index].PushBack(key)
	}
}

func (hs *MyHashSet) Remove(key int) {
	index := hash(key)
	for i := hs.data[index].Front(); i != nil; i = i.Next() {
		if i.Value.(int) == key {
			hs.data[index].Remove(i)
		}
	}
}

func (hs *MyHashSet) Contains(key int) bool {
	index := hash(key)
	for i := hs.data[index].Front(); i != nil; i = i.Next() {
		if i.Value.(int) == key {
			return true
		}
	}
	return false
}
